package com.bawei.controller;

import com.bawei.pojo.Examine;
import com.bawei.pojo.ExamineVo;
import com.bawei.pojo.Overtime;
import com.bawei.pojo.UserInfo;
import com.bawei.service.ExamineService;
import com.bawei.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("examine")
public class ExamineController {

    @Autowired
    private ExamineService examineService;
    @RequestMapping("list")
    public  String list(Model model){
        List<Examine> list=examineService.list();
        List arrayList = new ArrayList();
        for (Examine examine : list) {
            ExamineVo examineVo = new ExamineVo();
            examineVo.setExamine(examine);
            Overtime overtime=examineService.selectUid(examine.gettId());
            examineVo.setDes(overtime.getDes());
            UserInfo userInfo=examineService.getrealName(overtime.getUserId());
            examineVo.setRealName(userInfo.getRealName());
            arrayList.add(examineVo);
        }
        model.addAttribute("listMap", arrayList);
        return "forward:/system/examine.jsp";
    }

    @RequestMapping("detail")
    @ResponseBody
    public Overtime detail(String id){
        Examine examine=examineService.selectExamineById(id);

        return examineService.detail(examine.gettId());
    }

    @RequestMapping("updateStatus")
    @ResponseBody
    public ResultEntity updateStatus(String id, Integer status, HttpSession session){
        UserInfo userInfo= (UserInfo) session.getAttribute("user");
        examineService.updateStatus(id,status,userInfo.getRealName());
        return new ResultEntity("200", "成功");
    }
}
